<!DOCTYPE HTML SYSTEM>
<html>

<head>
<title>FNET POST Demo</title>
    <style type="text/css">
    <!--
    @import"fnet.css";
    -->
    </style>
	<script type="text/javascript">
		function fnetXMLHttpRequest(){
			var xmlHTTP = false;
			if (window.ActiveXObject)
				xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
			else if (window.XMLHttpRequest)
				xmlHTTP = new XMLHttpRequest();
			if (!xmlHTTP)
				alert("Cannot create an XMLHTTP instance!");
			return xmlHTTP;
		}
		function fnetPostRequest(){
		 		var xmlHTTP = fnetXMLHttpRequest();
                var data;
				data=document.getElementById("post_data").value;
				if(xmlHTTP != null){
				   	xmlHTTP.onreadystatechange = function(){
							if (xmlHTTP.readyState == 4)
								if (xmlHTTP.status != 200)
			            			alert("Submitting is failed.");
					};
					xmlHTTP.open("POST", "post.cgi", true);
					xmlHTTP.setRequestHeader("Content-length", data.length);
					xmlHTTP.send(data);
				}
		}
		function fnetGetRequest(){
			var xmlHTTP = fnetXMLHttpRequest();
			if(xmlHTTP != null)
			{
				xmlHTTP.onreadystatechange = function(){
					if (xmlHTTP.readyState == 4){
						if (xmlHTTP.status == 200)
				   			document.getElementById("view_data").value = xmlHTTP.responseText;
						else
		 					alert("Viewing is failed.");
					}
				};
 			   	xmlHTTP.open("GET", "post.cgi", true);
			   	xmlHTTP.setRequestHeader("If-Modified-Since", document.lastModified);
				xmlHTTP.send(null);
			}
		}
        function limitText(){
        	var limitField = document.getElementById("post_data");
            var limitNum = 50;
			if (limitField.value.length > limitNum) {
				limitField.value = limitField.value.substring(0, limitNum);
			} else {
				document.getElementById("counter").innerHTML = limitNum - limitField.value.length;
			}
		}
	</script>
</head>

<body>
	<h2>FNET POST Demo</h2>
    <table cellspacing="2">
	<th width="244">Submitting your input data:</th>
	<th width="244">Checking your submitted data:</th>
	<tr>
		<td>
 			<textarea id="post_data" rows="3" cols="29" wrap="soft" onpaste="limitText();" onkeydown="limitText();" onkeyup="limitText();"></textarea><br/>
			<input type="button" value="POST" onclick="fnetPostRequest();"/>
			<font size="1"> You have <span id="counter">50</span> characters left.</font>
		</td>
		<td>
        	<textarea id="view_data" rows="3" cols="29" readonly="readonly" wrap="soft"></textarea><br/>
            <input type="button" value="GET" onclick="fnetGetRequest();"/>
		</td>
	</tr>
	</table>
    <br/>
	<i>NOTE: This page submits the input data to the server using the POST method of HTTP protocol.</i>
</body>
</html>
